//
//  AppDelegate.swift
//  WJWeiBo
//
//  Created by wangjun on 16/7/19.
//  Copyright © 2016年 wangjun. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        
//        setNavBarStyle()
        
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
        self.window?.backgroundColor = UIColor.whiteColor()
        
//        setupDefautRootVC()
         self.window?.rootViewController = UINavigationController(rootViewController: WJComposeViewController())
        
        self.window?.makeKeyAndVisible()
        
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "switchRootVC:", name: weiBoSwitchRootVC , object: nil)
        
        return true
    }
    
    func switchRootVC(noti: NSNotification) {
        
        // 代表 OAuthVc -> WelComeVc
        if noti.object == nil {
            
            self.window?.rootViewController = WJWelcomeViewController()
        }else {
            // 代表WelComeVc -> MainVc
            // 由于当object 不为nil 切换的跟控制器均为MainVc
            self.window?.rootViewController = WJMainViewController()
        }
    }
    
    func setupDefautRootVC() {
        
        if WJUserAccountViewModel.shareTools.isLogin{
            
            if isNewVersion() {
                
            self.window?.rootViewController = WJNewFeatureViewController()
            
            }else{
                 self.window?.rootViewController = WJWelcomeViewController()
                
            }
    
        }else{
            
             self.window?.rootViewController = WJMainViewController()
        }
    }

    func isNewVersion() -> Bool{
 
        let currentVersion = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String

        let currentVersionD = Double(currentVersion)!
       
        let shAppVersion = "shAppVersion"
        
        let oldVersion = NSUserDefaults.standardUserDefaults().doubleForKey(shAppVersion)
      
        NSUserDefaults.standardUserDefaults().setDouble(currentVersionD, forKey: shAppVersion)
   
        return currentVersionD > oldVersion
    }
//
//    
//    
//
//    func setNavBarStyle() {
//        
//        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
//    }
//
//    deinit{
//        
//        NSNotificationCenter.defaultCenter().removeObserver(self)
//    }

}









